import { http } from '@/utils/http'

export interface LiveItem {
  liveId: number
  liveName: string
  chanelId: string
  chanelPassword: string
  creater: string
  startTimeStr: string
  categoryName: string
  frontImage: string
  runStatus: number
  statusStr: string
  isTeacher: number
  isOpen: number
  myUserTypeToThislive: number
  reserveCount: number
  countdown: string
}

export interface LiveData {
  totalCount: number
  items: LiveItem[]
}

export interface LiveListParams {
  pageIndex?: number
  pageSize?: number
  isMayTask?: boolean
}

/** 获取直播列表 */
export const getLiveList = ({
  pageIndex = 1,
  pageSize = 20,
  isMayTask = false,
}: LiveListParams = {}): Promise<IResData<LiveData>> => {
  return http.get<LiveData>('/api/MP/GetLiveList', {
    pageIndex,
    pageSize,
    isMayTask,
  })
}

/** 获取热门直播列表 */
export const getHotLiveList = (): Promise<IResData<LiveData>> => {
  return http.get<LiveData>('/api/MP/GetHotLiveList')
}

/* {
"id": 30,
"cover": "https://cpbuat.panzhi.com.cn:8266/data/1/2025/April/14/retechwing/b575c7e1dd7f129397d4a2b679ff205d.png",
"liveName": "直播测试E",
"startTime": "2025-04-22 18:10",
"endTime": "2025-04-22 20:00",
"teacher":{"teacherId": 5570, "teacherName": "直播测试账号", "teacherGoodAt": "水泵营销", "cover": "~/UploadFiles/UserPhoto/man.png"…},
"outline": "<p>AAAAAAAAAAA</p>",
"reservationCount": 0,
"channelId": "5702767",
"myUserTypeToThislive": 2,
"runStatus": 0,
"statusStr": "未开始"
}, */
export interface LiveDetail {
  id: number
  cover: string
  liveName: string
  startTime: string
  endTime: string
  teacher: {
    teacherId: number
    teacherName: string
    teacherGoodAt: string
    cover: string
  }
  outline: string
  reservationCount: number
  channelId: string
  myUserTypeToThislive: number
  runStatus: number
  statusStr: string
}

/** 获取课程直播详情 */
export const getCourseLiveDetail = (id: number): Promise<IResData<LiveDetail>> => {
  return http.get<LiveDetail>('/api/MP/CourseLiveDetail', { id })
}

/** 预约直播 */
export const reservationLive = (id: number): Promise<IResData<void>> => {
  return http.post<void>('/api/MP/ReservationLive?id=' + id)
}

/** 提交直播观看记录 在组件中，当用户开始观看直播时调用 */
export const submitWatchLive = (liveId: number, chanelId: string): Promise<IResData<any>> => {
  return http.get<any>('/api/MP/WatchLive', { liveId, chanelId })
}
